package cn.belong.jk.service;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.belong.jk.dao.ContractProductDao;
import cn.belong.jk.entity.ContractProduct;
import cn.belong.jk.util.UtilFuns;

@Service("contractproductService")
public class ContractProductServiceImpl implements ContractProductService {

	  	@Autowired
	    ContractProductDao contractProductDao;

		public List<ContractProduct> find(Map paraMap) {
			 return contractProductDao.find(paraMap);  
		}

		public ContractProduct get(Serializable id) {
			 return contractProductDao.get(id);  
		}

		public void insert(ContractProduct entity) {
		    //设置UUID  
			entity.setId(UUID.randomUUID().toString());  
		      
		    //自动计算总金额=数量*单价  ...修改，删除；同步合同金额  
		    if(UtilFuns.isNotEmpty(entity.getCnumber())  
		                &&UtilFuns.isNotEmpty(entity.getPrice())){  
		    	entity.setAmount(entity.getCnumber()*entity.getPrice());  
		        }  
		      
		    contractProductDao.insert(entity);   
			
		}

		public void update(ContractProduct entity) {
			
		    //自动计算总金额=数量*单价  ...修改，删除；同步合同金额  
		    if(UtilFuns.isNotEmpty(entity.getCnumber())  
		                &&UtilFuns.isNotEmpty(entity.getPrice())){  
		    	entity.setAmount(entity.getCnumber()*entity.getPrice());  
		        }  
			  contractProductDao.update(entity);  
			
		}

		//删除多个  
		
		public void delete(Serializable[] ids) {  
		    try {  
		        //先删除所有货物下的附件  
		        contractProductDao.deleteByContractProductById(ids);  
		    } catch (Exception e) {  
		        // TODO Auto-generated catch block  
		        e.printStackTrace();  
		    }  
		    contractProductDao.delete(ids);  
		}  
		  
		  
		//删除一个  

		public void deleteById(Serializable id) {  
		    Serializable[] ids={id};  
		    try {  
		        //先删除所有货物下的附件  
		        contractProductDao.deleteByContractProductById(ids);  
		    } catch (Exception e) {  
		        // TODO Auto-generated catch block  
		        e.printStackTrace();  
		    }  
		    contractProductDao.deleteById(id);  
		}  
	      
	  
	  


}
